1 00:00:00,500 --> 00:00:06,030 Hell who are they welcome to feed you on Javascript variables. 2 00:00:06,030 --> 00:00:12,690 Variables are containers that you can use to store values in. 3 00:00:13,230 --> 00:00:22,350 It's kind of like a little too eerie or memory holds value and that can be referenced later variable 4 00:00:22,410 --> 00:00:24,690 must have a name. 5 00:00:24,740 --> 00:00:28,270 And there are conditions in name in variables. 6 00:00:28,350 --> 00:00:37,070 For example you can not begin a variable name with any number you can't for example name it variable 7 00:00:37,230 --> 00:00:38,470 for cash. 8 00:00:38,520 --> 00:00:42,060 You can however name it cash 24. 9 00:00:42,060 --> 00:00:48,060 You can not use mathematical or logical operators in variable names. 10 00:00:48,060 --> 00:00:55,120 For example you can name a variable 7 star or 7 question mark consort. 11 00:00:55,150 --> 00:00:57,140 You can't use punctuation mark. 12 00:00:57,330 --> 00:01:03,810 However you can use an underscore to name variable names but that's the only exception. 13 00:01:03,900 --> 00:01:06,970 You can't use any other punch Nations. 14 00:01:07,200 --> 00:01:15,050 Jeb us group names must not contain spaces so you can have a variable name called Cash 24. 15 00:01:15,120 --> 00:01:19,000 And they can not be a space between the cash and the 24. 16 00:01:19,050 --> 00:01:26,860 So the names must contain no spaces variable names are case sensitive variable. 17 00:01:26,960 --> 00:01:32,430 The lower case X and upper case X are two different variables. 18 00:01:32,430 --> 00:01:41,670 You can not use any javascript key words or any key word that is part of the javascript language. 19 00:01:41,820 --> 00:01:49,410 You can't use that variable name for example you can't have a variable code alert something or prompt. 20 00:01:49,530 --> 00:01:52,820 Those are part of the javascript key word. 21 00:01:52,830 --> 00:01:57,730 The name on the variable itself is really up to us or to you. 22 00:01:57,930 --> 00:01:59,910 So more is better. 23 00:01:59,910 --> 00:02:06,530 The name you give is a variable represent the piece of data that you want to store. 24 00:02:06,540 --> 00:02:13,460 For example if you are storing details about customer accounts you can name the variable customer count 25 00:02:13,860 --> 00:02:16,310 so it makes it relevant or Shehan. 26 00:02:16,320 --> 00:02:23,160 If you are storing details about an address you can name the variable cost to address a variable I created 27 00:02:23,160 --> 00:02:27,720 using the key word var which is if you are in a lower case. 28 00:02:27,720 --> 00:02:32,230 I will be creating a sample variable in a few minutes. 29 00:02:32,250 --> 00:02:35,210 All right just before I create some variables. 30 00:02:35,220 --> 00:02:40,100 I just want to go through what I have spoken about so far. 31 00:02:40,280 --> 00:02:46,880 That variables are containers used to store values that can be referenced and used later. 32 00:02:47,130 --> 00:02:51,060 Variable names are case sensitive so you name it variable. 33 00:02:51,060 --> 00:02:56,050 Lower case X and try and change the value thinking it's an upper case X.. 34 00:02:56,070 --> 00:02:57,810 You may get some issues. 35 00:02:57,900 --> 00:03:03,560 Variables are created or declared using the key word and here are. 36 00:03:03,990 --> 00:03:07,420 You can not begin the variable names with no. 37 00:03:07,440 --> 00:03:12,610 E.g. 247 carriage you can reverse it like cash two for seven dollars. 38 00:03:12,630 --> 00:03:15,880 Group names must not have spaces between them. 39 00:03:15,990 --> 00:03:24,690 If fast cars tell us groupy was cannot be used like learned some plant variable without value is known 40 00:03:24,690 --> 00:03:26,240 as undefined. 41 00:03:26,280 --> 00:03:28,510 Also why is you arguing the variable of value. 42 00:03:28,530 --> 00:03:30,070 You can change it any time. 43 00:03:30,090 --> 00:03:33,200 So let's go ahead and create some variables. 44 00:03:33,240 --> 00:03:36,450 All right this is my sample script here. 45 00:03:36,450 --> 00:03:38,320 This is my text said it all. 46 00:03:38,340 --> 00:03:41,930 This is the page that this code here displays. 47 00:03:41,950 --> 00:03:45,270 So got one content which is this one tack here. 48 00:03:45,270 --> 00:03:53,020 Right so this is the javascript so what I need to focus on is the code between the script tag. 49 00:03:53,250 --> 00:03:56,210 So I've created a few variables here. 50 00:03:56,370 --> 00:04:02,560 The first one is a variable to chord X and it stores the value of 27. 51 00:04:02,570 --> 00:04:07,210 Next one is a variable called Y is stores of value of 38. 52 00:04:07,560 --> 00:04:15,030 And they've got the variables Z and values equal still x plus y have also gone at a variable called 53 00:04:15,030 --> 00:04:19,400 my car when a variable name is set up like it's called. 54 00:04:19,440 --> 00:04:25,080 Come all k so you be in with lower case and then the first letter is an upper case. 55 00:04:25,080 --> 00:04:29,600 I've also gone at a variable first name variable here. 56 00:04:29,640 --> 00:04:31,140 Hasn't got any value. 57 00:04:31,180 --> 00:04:36,090 My car hasn't got any value but these ones got a value. 58 00:04:36,120 --> 00:04:42,430 It's always good to declare your variables at the beginning of the script and also set a value. 59 00:04:42,450 --> 00:04:51,040 If you know what your values are so if I remove this comment run this alert. 60 00:04:51,360 --> 00:04:57,510 It should give me the value of x and y some say an alert. 61 00:04:57,540 --> 00:04:59,910 The result of a z z. 62 00:05:00,050 --> 00:05:00,660 Means. 63 00:05:00,660 --> 00:05:02,260 Variable said. 64 00:05:02,420 --> 00:05:07,430 So if I say that and run that it should show me my browser. 65 00:05:07,460 --> 00:05:09,790 So click run in Firefox. 66 00:05:10,190 --> 00:05:15,030 So the last 6 to 5 so do result of Z is 65 to Z. 67 00:05:15,040 --> 00:05:18,740 It's a tool of x and y. 68 00:05:19,790 --> 00:05:24,890 So next if I run let me comment this again. 69 00:05:26,780 --> 00:05:36,400 If I run this piece of code here you see what it says go run. 70 00:05:40,050 --> 00:05:48,610 It says on defying new reason it is undefined because I have not set a value for my car. 71 00:05:48,600 --> 00:05:49,830 I've alerted my car. 72 00:05:49,830 --> 00:05:51,250 Boy hasn't got a family. 73 00:05:51,420 --> 00:05:56,990 That's why he's called on to find out what's your variable boys created. 74 00:05:57,000 --> 00:06:01,170 You can't always change the values later. 75 00:06:01,260 --> 00:06:04,210 So for example I've already declared a variable x. 76 00:06:04,350 --> 00:06:11,260 I can change that value from 27 any time variable has already been declared or created. 77 00:06:11,390 --> 00:06:18,490 Right so this I have now given the value I have now set a value for the variable. 78 00:06:18,510 --> 00:06:21,730 My car remember when I created it. 79 00:06:21,780 --> 00:06:23,640 I didn't create a set of value. 80 00:06:23,650 --> 00:06:29,520 It's always good to set a value if you know what the value should be but sometimes you don't always 81 00:06:29,520 --> 00:06:30,610 know. 82 00:06:30,660 --> 00:06:32,040 So I've said it variable. 83 00:06:32,120 --> 00:06:40,080 So the variable my car and have now come down here and giving it a value of reinke for that. 84 00:06:40,200 --> 00:06:47,690 So now alert for this alert comment let my car it will come up. 85 00:06:47,700 --> 00:06:48,590 Ring true. 86 00:06:48,900 --> 00:06:58,640 So let me see that run that ring from above because I am now giving it value. 87 00:06:59,960 --> 00:07:04,070 So variable can always be called twice. 88 00:07:04,110 --> 00:07:09,740 It has been declared so calling a variable or you need to do is called a name like it Don here. 89 00:07:09,900 --> 00:07:17,670 I've already declared the variable of my car so to call it does alert the message my car and then he 90 00:07:17,670 --> 00:07:20,950 shows up in the pop up window. 91 00:07:21,200 --> 00:07:26,060 Right so Im going to comment this out. 92 00:07:26,700 --> 00:07:31,410 All right Im just going to alert this variable here called first name. 93 00:07:31,410 --> 00:07:36,380 Also when you are calling your variables make sure you call them by their right name. 94 00:07:36,540 --> 00:07:43,680 For example if you notice a variable name here is come or case that is first and then the other part 95 00:07:43,680 --> 00:07:46,140 of its first letter is capital. 96 00:07:46,140 --> 00:07:54,840 If I came here and call the first name without a capital N the computer program programming language 97 00:07:54,840 --> 00:07:59,070 will not know what I'm talking about javascript would just throw up an error or say I don't know what 98 00:07:59,070 --> 00:07:59,400 you mean. 99 00:07:59,400 --> 00:08:00,170 Sorry. 100 00:08:00,240 --> 00:08:04,150 So you must name them or call them what you name them. 101 00:08:04,170 --> 00:08:07,580 For example here I've called variable X.. 102 00:08:07,620 --> 00:08:15,030 If I come here and call a variable or PI case X it will not know what I'm talking about because the 103 00:08:15,030 --> 00:08:16,680 case is sensitive. 104 00:08:16,920 --> 00:08:22,800 So if I run this now it will come on but on defined because of not giving it a value. 105 00:08:22,920 --> 00:08:25,550 When I declared it or created it. 106 00:08:25,680 --> 00:08:27,300 So click on run 107 00:08:30,060 --> 00:08:36,950 comes up as defined so I can now go ahead later and then give it a value. 108 00:08:37,150 --> 00:08:40,740 K I have now given this variable here. 109 00:08:40,740 --> 00:08:45,540 The first new variable have now giving it a value of you. 110 00:08:45,870 --> 00:08:47,010 So give is now. 111 00:08:47,010 --> 00:08:48,940 Got to name value. 112 00:08:49,110 --> 00:08:53,580 So if I run a left first name it should come up. 113 00:08:53,610 --> 00:08:57,760 You do me so let me run that. 114 00:09:01,190 --> 00:09:08,730 All right so come on we you demi no longer says on defined because Eve has now got a value. 115 00:09:09,140 --> 00:09:16,270 Also once a variable has been declared or created you can always change the name. 116 00:09:16,280 --> 00:09:18,310 All it is is a container label. 117 00:09:18,320 --> 00:09:21,180 You can always change what you've got inside. 118 00:09:21,380 --> 00:09:23,450 So what you store can always change. 119 00:09:23,450 --> 00:09:34,790 So for example if I want to change this name from Demi to something else say to Jack has put Jack there. 120 00:09:37,820 --> 00:09:41,840 So I changed that to Jack save that. 121 00:09:41,840 --> 00:09:42,930 Run it. 122 00:09:46,420 --> 00:09:49,120 It's now coming up with the value of Jack. 123 00:09:49,240 --> 00:09:50,260 So I've changed. 124 00:09:50,290 --> 00:09:56,770 What's in the container so you can always change the variable once it's being declared you can change 125 00:09:56,830 --> 00:10:00,220 the value of the variable once it is been declared. 126 00:10:00,430 --> 00:10:04,790 So be careful that variable names are case sensitive. 127 00:10:05,450 --> 00:10:07,000 Okay I apologize. 128 00:10:07,000 --> 00:10:12,440 This video has gone on a bit longer than I expected. 129 00:10:12,460 --> 00:10:14,800 There was so much I wanted to cover. 130 00:10:14,920 --> 00:10:16,310 I do apologize. 131 00:10:16,320 --> 00:10:17,430 It's too long. 132 00:10:17,830 --> 00:10:19,300 Thank you so much for watching. 133 00:10:19,300 --> 00:10:22,540 I hope the video has made sense if it hasn't. 134 00:10:22,540 --> 00:10:31,210 Please feel free to contact me and I you now have some kind of understanding of what variables are how 135 00:10:31,210 --> 00:10:32,660 to create them. 136 00:10:32,690 --> 00:10:35,260 Also thank you so much for watching. 137 00:10:35,260 --> 00:10:36,230 Bye for now.